﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;

public partial class UserLogin_Developer_ProjectIndex : System.Web.UI.Page
{

    DataClassesDataContext db = new DataClassesDataContext();

    protected void Page_Load(object sender, EventArgs e)
    {
        

        if (!IsPostBack)
        {
            string projectName = Request.QueryString["ProjectName"];
            myBindProjectData(projectName);

            string Identity = Session["Identity"].ToString();
            if (Identity == "ProjectManager")
                MyProjectDropDownList.Enabled = true;
            else
            {
                MyProjectDropDownList.Enabled = false;
            }


        }
        
        
    }

    protected void myBindProjectData(string projectName)
    {

        var result = (from r in db.ProjectInfo
                      where r.ProjectName == projectName
                      select r).FirstOrDefault();


        ProjectInfo tmp = (ProjectInfo)result;
        string ProjectName = tmp.ProjectName;
        string ProjectManager = tmp.ProjectManager;
        string ProjectStartEndTime = tmp.StartTime + " -- " + tmp.EndTime;
        string Status = tmp.Status;
        string Type = tmp.Type;
        string Notice = "暂无公告";
        string Background = tmp.Background;

        string language1 = null;
        string language2 = null;
        string language3 = null;
        string language4 = null;
        string language5 = null;
        string language6 = null;
       


        string people = tmp.ProjectMember.Trim();
        string pattern = @"\s+";
        string[] peopleNames = System.Text.RegularExpressions.Regex.Split(people, pattern);

        foreach(string peopleName in peopleNames)
        {

            var res = (from r in db.UserInfo
                      where r.Name == peopleName
                      select r).FirstOrDefault();


            string skills = ((UserInfo)res).Skill.Trim();

            string skill = System.Text.RegularExpressions.Regex.Split(skills, pattern)[0];

            if (skill == "C语言")
            {
                language1 += peopleName + " ";
            }
            else if (skill == "C++")
            {
                language2 += peopleName + " ";
            }
            else if (skill == "C#")
            {
                language3 += peopleName + " ";
            }
            else if (skill == "Java")
            {
                language4 += peopleName + " ";
            }
            else if (skill == "Python")
            {
                language5 += peopleName + " ";
            }
            else if (skill == "PHP")
            {
                language6 += peopleName + " ";
            }


        }

        string Extender = "暂无插件";
        string Database = "暂无数据库";



        //----------------
        MyProjectName.Text = ProjectName;
        MyProjectManager.Text = ProjectManager;
        MyProjectStartEndTime.Text = ProjectStartEndTime;

        if (Status == "创建")
        {
            MyProjectDropDownList.SelectedIndex = 1;
        }
        else if(Status=="启动")
        {
            MyProjectDropDownList.SelectedIndex = 2;
        }
        else if (Status == "完成")
        {
            MyProjectDropDownList.SelectedIndex = 3;
        }
        else if (Status == "交付")
        {
            MyProjectDropDownList.SelectedIndex = 4;
        }

        MyType.Text = Type;
        MyNotice.Text = Notice;
        MyBackground.Text = Background;
        Mylanguage1.Text = language1 == null ? "无" : language1;
        Mylanguage2.Text = language2 == null ? "无" : language2;
        Mylanguage3.Text = language3 == null ? "无" : language3;
        Mylanguage4.Text = language4 == null ? "无" : language4;
        Mylanguage5.Text = language5 == null ? "无" : language5;
        Mylanguage6.Text = language6 == null ? "无" : language6;
        MyExtender.Text = Extender;
        MyDatabase.Text = Database;

    }

    protected void MyProjectDropDownList_SelectedIndexChanged(object sender, EventArgs e)
    {
        string NowStatus = MyProjectDropDownList.SelectedItem.Text;

        var result = (from r in db.ProjectInfo
                     where r.ProjectName == Request.QueryString["ProjectName"]
                     select r).FirstOrDefault();

        result.Status = NowStatus;

        db.SubmitChanges();

    }
}